{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7123b694",
   "metadata": {},
   "source": [
    "<i>Copyright (c) Recommenders contributors.</i>\n",
    "\n",
    "<i>Licensed under the MIT License.</i>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "17b046f1",
   "metadata": {},
   "source": [
    "# Programmatic execution of Jupyter notebooks\n",
    "\n",
    "This is a Jupyter notebook that can be paramtrized to be able to execute it externally. Also, we provide utilities to extract the outputs computed by the notebook.\n",
    "\n",
    "The main use case for this is to test the notebooks.\n",
    "\n",
    "**NOTE:**\n",
    "Make sure you parametrize the cell where you want to inject parameters. For doing it, go to View, Cell toolbar, Tags. In the text box, add `parameters`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "494d7493",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.8.13 (default, Mar 28 2022, 11:38:47) \n",
      "[GCC 7.5.0]\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import sys\n",
    "\n",
    "from recommenders.utils.notebook_utils import store_metadata\n",
    "\n",
    "print(sys.version)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "298e0205",
   "metadata": {
    "tags": [
     "parameters"
    ]
   },
   "outputs": [],
   "source": [
    "# Parameters\n",
    "a = 1\n",
    "b = \"M\"\n",
    "c = 5 # This is a comment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5c802f7c",
   "metadata": {},
   "outputs": [],
   "source": [
    "def plus2(num):\n",
    "    return num + 2\n",
    "\n",
    "def is_letter(letter):\n",
    "    if letter == \"M\":\n",
    "        return True\n",
    "    elif letter != \"M\" and isinstance(letter, str):\n",
    "        return letter\n",
    "    else:\n",
    "        raise ValueError()\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7f4af7c2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "response1 = plus2(a)\n",
    "print(response1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "004ba65c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "response2 = is_letter(b)\n",
    "print(response2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ed0e55a",
   "metadata": {},
   "outputs": [],
   "source": [
    "response3 = plus2(c)\n",
    "print(response3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0de1951d",
   "metadata": {},
   "outputs": [],
   "source": [
    "store_metadata(\"response1\", response1)\n",
    "store_metadata(\"response2\", response2)\n",
    "store_metadata(\"response3\", response3)"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
